
lazy val commonSettings = Seq(
  organization := "com.mikelouis.test.scala.sbt.tutorial",
  version := "0.0.1",
  scalaVersion := "2.11.6"
)

lazy val sbtTutorialLib = (project in file(".")).
  settings(commonSettings: _*).
  settings(
    name := "sbtTutorialLib",

    //    sampleStringTask := System.getProperty("user.home"),
    //
    //    sampleIntTask := {
    //      val sum = 1 + 2
    //      println("sum: " + sum)
    //      sum
    //    }

    /** Execution semantics of tasks: in this case, startServer and stopServer task will execute simultaneously */
//    startServer := {
//      println("starting...")
//      Thread.sleep(500)
//    },
//    stopServer := {
//      // startServer.value
//      println("stopping...")
//      Thread.sleep(500)
//    },
//    sampleIntTask := {
//      // If the task has dependencies, you’d reference their value using value
//      startServer.value
//      val sum = 1 + 2
//      println("sum: " + sum)
//      stopServer.value // THIS WON'T WORK
//      sum
//    },
//    sampleStringTask := {
//      startServer.value
//      val s = sampleIntTask.value.toString
//      println("s: " + s)
//      s
//    }

    /** cleanup task: The last operation should become the task that depends on other intermediate tasks */
      startServer := {
      println("starting...")
      Thread.sleep(500)
    },
    sampleIntTask := {
      startServer.value
      val sum = 1 + 2
      println("sum: " + sum)
      sum
    },
    sampleStringTask := {
      startServer.value
      val s = sampleIntTask.value.toString
      println("s: " + s)
      s
    },
    sampleStringTask := {
      val old = sampleStringTask.value
      println("stopping...")
      Thread.sleep(500)
      old
    }

    /** use plain scala: Another way of making sure that something happens after some other thing is to use Scala. Implement a simple function in project/ServerUtil.scala*/
    // TODO
  )


/** settings and tasks */
// lazy val sampleStringTask = taskKey[String]("A sample string task")
// lazy val sampleIntTask = taskKey[Int]("A sample int task")

lazy val startServer = taskKey[Unit]("start server")
lazy val stopServer = taskKey[Unit]("stop server")
lazy val sampleIntTask = taskKey[Int]("A sample int task.")
lazy val sampleStringTask = taskKey[String]("A sample string task.")